/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//package CERC2011;

import java.util.Arrays;
import java.util.Scanner;

/**
 *
 * @author andres
 */
public class C {
    public static void main(String Args[]){
        Scanner sc = new Scanner(System.in);
        boolean primero=true;
        while (true){
            int M = sc.nextInt();
            int Q= sc.nextInt();
            if (M==Q && Q==0){return;}
            if (!primero){
                System.out.println("");
            }
            Objeto[] vec = new Objeto[M];
            Rango[] vecRang = new Rango[Q];
            
            for (int i=0;i<M;i++){
                vec[i]=new Objeto(i,sc.nextInt());
            }
            
            for (int i=0;i<Q;i++){
                int num= sc.nextInt()-1;
                int Num= sc.nextInt()-1;
                vecRang[i]= new Rango(num, Num);
            }
            
            Arrays.sort(vec);
            
            for (int i=0;i<vec.length-1;i++){
                Objeto o= vec[i];
                if (o.unico){continue;}
                for (int j=i+1;j<vec.length;j++){
                    if (vec[i].valor==vec[j].valor){
                        for (Rango r: vecRang){
                            if (!r.Unico){continue;}
                         //   System.out.println(vec[i].valor+" "+vec[i].posicion+" "+vec[j].posicion+" "+r.Menor);
                            if (vec[i].posicion>=r.Menor && vec[j].posicion>=r.Menor && vec[i].posicion<=r.Mayor && vec[j].posicion<=r.Mayor){
                                r.Unico=false;
                                r.valor=vec[i].valor;
                            }
                        }
                    }else{
                      //  i=j;
                        break;
                    }
                }
            }
            System.out.println(Arrays.toString(vec));
            for (Rango r: vecRang){
                System.out.println((r.Unico)?"OK":r.valor);    
            }
            primero=false;
        }
    }
}

class Objeto implements  Comparable<Object> {
    public int posicion;
    public int valor;
    public boolean unico; 
    public Objeto(int posicion, int valor) {
        this.posicion = posicion;
        this.valor = valor;
        unico=true;
    }

    @Override
    public int compareTo(Object t) {
        Objeto o = (Objeto)t;
        boolean val=valor-o.valor==0;
       if (val){
            o.unico=false;
            unico=false;
        }
        if (val){
            return (this.posicion-o.posicion);
        }
        return valor-o.valor;
    }

    @Override
    public String toString() {
        return (this.valor+"="+this.posicion);
    }
    
    
}

class Rango{
    public int Menor;
    public int Mayor;
    public boolean Unico=true;
    public int valor;
    public Rango(int Menor, int Mayor) {
        this.Menor = Menor;
        this.Mayor = Mayor;
    }
    
}